package com.webull.information.center.carwler.job;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.Collection;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;

import com.webull.information.center.carwler.common.util.ThumbnailatorUtil;
import com.webull.information.center.carwler.common.util.ThumbnailatorUtil.NewsThumb;

public class CutPicuter {

	public static void main(String[] args) throws IOException {
		// ThumbnailatorUtil
		Collection<File> files = FileUtils.listFiles(new File("C:/Users/smj/Desktop/0_"), new MyFileFilter(),
				new MyFileFilter());
		FileUtils.forceMkdir(new File("C:/Users/smj/Desktop/0"));
		File[] fffs = files.toArray(new File[0]);
		for (int i = 0; i < fffs.length; i++) {
			NewsThumb tb = ThumbnailatorUtil.converNewsThumb(FileUtils.readFileToByteArray(fffs[i]),200);
			if (tb.getName().length() > 0) {
				FileUtils.copyToFile(new ByteArrayInputStream(tb.getBytes()),
						new File("C:/Users/smj/Desktop/0/" + (i + 1) + ".jpg"));
			}
		}
		System.out.println(files);

	}

	public static class MyFileFilter implements IOFileFilter {

		@Override
		public boolean accept(File file) {
			return true;
		}

		@Override
		public boolean accept(File dir, String name) {
			return true;
		}

	}
}
